<template>
  <div class="_cart _m-auto _box-400p _p20">
    <h2 class="_m-b-20">资源录入</h2>
    <el-form :model="form">
      <el-form-item label="资源父级">
        <com-select
          :dictList="pResource"
          :memo="'资源父级'"
          v-model="form.pid"
        />
      </el-form-item>
      <el-form-item label="资源类型">
        <el-radio-group v-model="form.type">
          <el-radio-button label="resource">资源</el-radio-button>
          <el-radio-button label="group">分组</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="资源名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="资源内容">
        <el-input v-model="form.content" />
      </el-form-item>
      <el-form-item label="资源图标">
        <com-upload v-model:file-key="form.icon" />
      </el-form-item>
    </el-form>
    <div class="_text-a-c">
      <el-button @click="$emit('close')">取消</el-button>
      <el-button type="primary" @click="save()">保存</el-button>
    </div>
  </div>
</template>

<script>
import ComSelect from "@/components/com-select/com-select.vue";
import ComUpload from "@/components/com-upload/com-upload.vue";
import toolAction from "@/tool/http/tool-action";

let actionAccountMenus = toolAction.init("account_menu");

export default {
  components: {
    ComUpload,
    ComSelect,
  },
  data() {
    return {
      form: {
        type: "resource",
        pid: "0",
      },
      pResource: [],
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      // let accountMenus = await actionAccountMenus.list({ "rules"});
      actionAccountMenus
        .tree({
          rules: {
            resource_id__eq: "",
          },
        })
        .then((res) => {
          this.pResource = [{ name: "根目录", val: "0", children: res }];
        });
    },
    save() {
      toolAction
        .run("action-account-com-resource-create", 1, this.form)
        .then(() => {
          this.$comStore.login.refreshRes();
          this.$emit("close");
        });
    },
  },
};
</script>

<style></style>
